package com.operation.controller;

import com.operation.entity.UserInfo;
import com.operation.service.UserService;

import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AssertionHolder;
import org.jasig.cas.client.validation.Assertion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframeworw35k.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.swing.text.SimpleAttributeSet;

//@RequestMapping("page")
@Controller
public class PageController {
    @Autowired
    UserService userService;









    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public String page() {
        String page = null;
        UserInfo userInfo = new UserInfo();
        Assertion assertion = AssertionHolder.getAssertion();
        AttributePrincipal ap = assertion.getPrincipal();
        if (userService.isExist(Long.valueOf(ap.getName())) == 1) {
            System.out.println("++++++++++++++++++++++++++++++用户不存在");
            /*userInfo.setUserAccount(Long.valueOf(ap.getName()));
            userService.add(userInfo);*/
        } else {
            userInfo.setUserAccount(Long.valueOf(ap.getName()));
            userInfo.setUserPassword("1");
            if (userService.isIt(userInfo) != null) {
                userService.updateIsOnline(userInfo);
            }
            System.out.println("++++++++++++++++++++++++++++++用户已存在");
        }
        return "PCrepairman_one";
    }

   // @RequestMapping(value = "jsp/PCrepairman", method = RequestMethod.GET)
   //public ModelAndView toPage(@PathVariable("jsp") String jsp,@PathVariable("PCrepairman") String PCrepairman){
    //  ModelAndView mv = new ModelAndView(jsp+"/"+PCrepairman);
      //  return mv;} @RequestMapping(value = "/detail/{jobNumber}",method = RequestMethod.GET)
    //           public String pageDetail(Model modelone,@PathVariable String jobNumber,@PathVariable String receiveOne) {
    //             modelone.ad"dAttribute("jobNumber",jobNumber);
    //                return modelone";
    //            }




    //新增分页开始
    @RequestMapping(value = "/PCrepairman_one",method=RequestMethod.GET)
    public String PCrepairman_one(){
        return "PCrepairman_one";
    }

    @RequestMapping(value= "/PCrepairman_two",method = RequestMethod.GET)
    public String PCrepairman_two(){
        return "PCrepairman_two";
    }

    @RequestMapping(value= "/PCrepairman_three",method = RequestMethod.GET)
    public String PCrepairman_three(){
        return "PCrepairman_three";
    }

    @RequestMapping(value= "/PCrepairman_four",method = RequestMethod.GET)
    public String PCrepairman_four(){
        return "PCrepairman_four";
    }



    //新增分页开始
    @RequestMapping(value = "/complainli",method = RequestMethod.GET)
    public  String complainli(){
        return "complainli";
    }

    @RequestMapping(value = "/ordermanageli",method = RequestMethod.GET)
    public String ordermanageli(){
        return "ordermanageli";
    }

    @RequestMapping(value = "/totalorderli",method = RequestMethod.GET)
    public String totalorderli(){
        return "totalorderli";
    }

    @RequestMapping(value = "/worktypeli",method = RequestMethod.GET)
    public String worktypeli(){
        return "worktypeli";
    }





    //頁面跳轉代碼測試



//    @RequestMapping(value = "/createli",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
//    public String creatework(){
//        return "createli";
//    }
//
//
//
//    @RequestMapping(value = "/faultli",method = RequestMethod.GET)
//    public String faultli(){
//        return "faultli";
//    }
//
//
//    @RequestMapping(value = "/performancesli",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
//    public String perfromancesli(){
//        return "perfromancesli";
//    }
//
//
//
//    @RequestMapping(value = "/websiteli",method = RequestMethod.GET)
//    public String websiteli(){
//        return "websiteli";
//    }



    // @RequestMapping(value = "jsp/PCrepairman", method = RequestMethod.GET)
    //public ModelAndView toPage(@PathVariable("jsp") String jsp,@PathVariable("PCrepairman") String PCrepairman){
    //  ModelAndView mv = new ModelAndView(jsp+"/"+PCrepairman);
    //  return mv;
    //  }


    //首页新增分页跳转
    @RequestMapping(value = "/homePage",method=RequestMethod.GET)
    public  String homepage() {
        return "homePage";
    }

    @RequestMapping(value ="/progressRepair",method=RequestMethod.GET)
    public String progressRepair() {
        return "progressRepair";
    }

    @RequestMapping(value = "/historicalWorkList",method=RequestMethod.GET)
    public  String historicalWorkList() {
        return "historicalWorkList";
    }

    @RequestMapping(value = "/personalData",method=RequestMethod.GET)
    public  String personalData() {
        return "personalData";
    }











    @RequestMapping(value = "/detail/{jobNumber}", method = RequestMethod.GET)
    public String pageDetail(Model model, @PathVariable String jobNumber) {
        model.addAttribute("jobNumber", jobNumber);
        return "message_detail";
    }

    @RequestMapping( value = "/onlinePersonnel/{jobNumber}/{receiveOne}", method = RequestMethod.GET)
    public String onlinePersonnel(Model model, @PathVariable String jobNumber, @PathVariable String receiveOne) {
        model.addAttribute("jobNumber", jobNumber);
            model.addAttribute("receiveOne", receiveOne);
        return "go_operators";
}
}
